<template>
  <view class="content">
    <u-sticky :h5NavHeight="0">
      <!-- #ifndef MP-TOUTIAO -->
      <singleHeader pageTitle="优惠券"></singleHeader>
      <!-- #endif -->
      <pageHeader :items="items" :index="status" @change="change"> </pageHeader>
    </u-sticky>

    <pageList :items="list"></pageList>
    <toolsMore :status="moreStatus"></toolsMore>

    <view class="submit">
      <view class="m-btn"> 添加优惠券 </view>
    </view>
  </view>
</template>

<script>
import singleHeader from "@/components/diySystemPage/components/singleHeader/index.vue";
import pageHeader from "./components/page-header.vue";
import pageList from "./components/page-list.vue";
import toolsMore from "@/components/tools/tools-more.vue";

// import { storeAdminOrderList, storeAdminOrderCancel } from "@/api/admin";

export default {
  components: {
    singleHeader,
    pageHeader,
    pageList,
    toolsMore,
  },

  data() {
    return {
      status: 0,
      items: [
        { name: this.$t("newAdmin.order.all"), id: 0 },
        { name: this.$t("coupon.used"), id: 1 },
        { name: this.$t("coupon.expire"), id: 2 },
      ],

      list: [],
      moreStatus: 1,
      page: 1,
      isEnd: false,
      item: null,
    };
  },

  computed: {},

  onLoad(opi) {
    this.$utils.hideShareMenu();

    if (opi.id) {
      this.status = parseInt(opi.id);
    }
  },

  onShow() {
    this.clearData();
    // this.Emit.$on("handleList", this.handleList);
    // this.Emit.$on("handleMenu", this.handleMenu);
  },

  onHide() {
    // this.Emit.$off("handleList");
    // this.Emit.$off("handleMenu");
  },

  methods: {
    handleList(type, item) {
      switch (type) {
        case "cancel":
          // storeAdminOrderCancel({
          //   id: item.id,
          // }).then((res) => {
          //   if (res.code === 0) {
          //     this.clearData();
          //   }
          //   this.$utils.toast(res.msg);
          // });
          break;
      }
    },

    clearData() {
      this.page = 1;
      this.isEnd = false;
      this.list = [];

      this.storeAdminOrderList();
    },

    change(status) {
      // this.status = status;
      // this.clearData();
    },

    storeAdminOrderList() {
      let { list: oldList, page: pageNo, status, date_range } = this;

      // this.moreStatus = 2;
      // storeAdminOrderList({
      //   pageNo,
      //   status,
      //   pageSize: 20,
      //   ...date_range,
      // })
      //   .then((res) => {
      //     uni.stopPullDownRefresh();
      //     this.moreStatus = 1;

      //     if (res.code === 0) {
      //       let { list, totalCount } = res.data,
      //         count = parseInt(totalCount);

      //       list.forEach((el) => {
      //         el.checked = false;
      //       });

      //       if (list.length) {
      //         oldList.push(...list);
      //         this.page = this.page + 1;
      //       }

      //       if (oldList.length >= count) {
      //         this.isEnd = true;
      //         this.moreStatus = 3;
      //       }
      //     }
      //   })
      //   .catch(() => {
      //     this.moreStatus = 1;
      //     uni.stopPullDownRefresh();
      //   });
    },
  },

  onReachBottom() {
    if (this.isEnd) {
      return;
    }

    this.storeAdminOrderList();
  },

  onPullDownRefresh() {
    this.clearData();
  },
};
</script>

<style lang="less" scoped>
.content {
  position: relative;
  background: #f2f2f2;
  min-height: 100vh;
  padding-bottom: calc(env(safe-area-inset-bottom) + 120rpx);
  box-sizing: border-box;
}

.submit {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  background: #fff;
  box-sizing: border-box;
  padding: 10rpx 36rpx calc(env(safe-area-inset-bottom) + 10rpx);
}

.m-btn {
  height: 80rpx;
  background: #f0250e;
  border-radius: 32px;
  text-align: center;
  color: #fff;
  font-size: 32rpx;
  line-height: 80rpx;
}
</style>
